package com.tlgen.controller.student;

import com.tlgen.model.AvatarFile;
import com.tlgen.model.RespBean;
import com.tlgen.service.AvatarFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: tlgen
 * @Discription:
 */
@RestController
@RequestMapping("/student/avatar")
public class AvatarFileController {

    @Autowired
    AvatarFileService avatarFileService;

    @GetMapping("/")
    public List<AvatarFile> getAllAvatarFiles() {
        return avatarFileService.getAllFiles();
    }

    @PostMapping("/")
    public RespBean addAvatarFile(@RequestBody AvatarFile AvatarFile) {
        if (avatarFileService.addFile(AvatarFile) == 1) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

    @PutMapping("/")
    public RespBean updateAvatarFile(@RequestBody AvatarFile AvatarFile) {
        if (avatarFileService.updateFile(AvatarFile) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    @DeleteMapping("/{id}")
    public RespBean deleteAvatarFileById(@PathVariable Integer id) {
        if (avatarFileService.deleteFileById(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    @DeleteMapping("/")
    public RespBean deleteAvatarFileByIds(Integer[] ids) {
        if (avatarFileService.deleteFileByIds(ids) == ids.length) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }
}
